package mes.kanban.util;


import java.util.Date;

/** UUID 工具类
 * 
 */
public enum UUID {

    INSTANCE;

    //定义一个最大增长数
    private static final int MAX_COUNT = 1000;
    //定义用于递增的参数
    private static int count = 1;

    private static final String TGA = "RQD";



    //随机流水号
    public synchronized String uuid(){
        if(count > MAX_COUNT){
            count = 1;
        }
        String random = TGA + DateUtil.DateToString(new Date(), "yyyymmddhhmmss") + autoAddCode(count+"", 4);
        count ++;
        return random;
    }

    public static String getUUID(){
        return java.util.UUID.randomUUID().toString().replaceAll("-","");
    }

    //自动补全
    private static String autoAddCode(String target, int length){
        int strLen = target.length();
        StringBuffer sb = new StringBuffer("");
        while (strLen < length){
            sb.append("0");
            strLen ++;
        }
        return sb.append(target).toString();
    };
}
